{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import os\n",
    "import rbm   \n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\am\\Anaconda3\\envs\\tf-gpu-1p3\\lib\\site-packages\\ipykernel\\__main__.py:4: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Toy Story (1995)</td>\n",
       "      <td>Animation|Children's|Comedy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Jumanji (1995)</td>\n",
       "      <td>Adventure|Children's|Fantasy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Grumpier Old Men (1995)</td>\n",
       "      <td>Comedy|Romance</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Waiting to Exhale (1995)</td>\n",
       "      <td>Comedy|Drama</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Father of the Bride Part II (1995)</td>\n",
       "      <td>Comedy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0                                   1                             2\n",
       "0  1                    Toy Story (1995)   Animation|Children's|Comedy\n",
       "1  2                      Jumanji (1995)  Adventure|Children's|Fantasy\n",
       "2  3             Grumpier Old Men (1995)                Comedy|Romance\n",
       "3  4            Waiting to Exhale (1995)                  Comedy|Drama\n",
       "4  5  Father of the Bride Part II (1995)                        Comedy"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Loading in the movies dataset\n",
    "dir = os.getcwd()\n",
    "path = dir +'\\movie_data\\movies.dat'\n",
    "movies_df = pd.read_csv(path, sep='::', header=None)\n",
    "movies_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\am\\Anaconda3\\envs\\tf-gpu-1p3\\lib\\site-packages\\ipykernel\\__main__.py:4: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1193</td>\n",
       "      <td>5</td>\n",
       "      <td>978300760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>661</td>\n",
       "      <td>3</td>\n",
       "      <td>978302109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>914</td>\n",
       "      <td>3</td>\n",
       "      <td>978301968</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>3408</td>\n",
       "      <td>4</td>\n",
       "      <td>978300275</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2355</td>\n",
       "      <td>5</td>\n",
       "      <td>978824291</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0     1  2          3\n",
       "0  1  1193  5  978300760\n",
       "1  1   661  3  978302109\n",
       "2  1   914  3  978301968\n",
       "3  1  3408  4  978300275\n",
       "4  1  2355  5  978824291"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Loading in the movies dataset\n",
    "#dir = os.getcwd()\n",
    "path = dir + '\\movie_data\\\\ratings.dat'\n",
    "ratings_df = pd.read_csv(path, sep='::', header=None)\n",
    "ratings_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "movies_df.columns = ['MovieID', 'Title', 'Genre']\n",
    "ratings_df.columns = ['UserID', 'MovieID', 'Rating', 'Time']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MovieID</th>\n",
       "      <th>Title</th>\n",
       "      <th>Genre</th>\n",
       "      <th>List_Index</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Toy Story (1995)</td>\n",
       "      <td>Animation|Children's|Comedy</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Jumanji (1995)</td>\n",
       "      <td>Adventure|Children's|Fantasy</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Grumpier Old Men (1995)</td>\n",
       "      <td>Comedy|Romance</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Waiting to Exhale (1995)</td>\n",
       "      <td>Comedy|Drama</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Father of the Bride Part II (1995)</td>\n",
       "      <td>Comedy</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   MovieID                               Title                         Genre  \\\n",
       "0        1                    Toy Story (1995)   Animation|Children's|Comedy   \n",
       "1        2                      Jumanji (1995)  Adventure|Children's|Fantasy   \n",
       "2        3             Grumpier Old Men (1995)                Comedy|Romance   \n",
       "3        4            Waiting to Exhale (1995)                  Comedy|Drama   \n",
       "4        5  Father of the Bride Part II (1995)                        Comedy   \n",
       "\n",
       "   List_Index  \n",
       "0           0  \n",
       "1           1  \n",
       "2           2  \n",
       "3           3  \n",
       "4           4  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_df['List_Index'] = movies_df.index\n",
    "movies_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MovieID</th>\n",
       "      <th>List_Index</th>\n",
       "      <th>UserID</th>\n",
       "      <th>Rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   MovieID  List_Index  UserID  Rating\n",
       "0        1           0       1       5\n",
       "1        1           0       6       4\n",
       "2        1           0       8       4\n",
       "3        1           0       9       5\n",
       "4        1           0      10       5"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Merging two dataframes using left Join\n",
    "\n",
    "merged_df = pd.merge(movies_df, ratings_df[['UserID', 'MovieID','Rating']], on='MovieID')\n",
    "merged_df = merged_df.drop('Title', axis=1).drop('Genre', axis=1)\n",
    "merged_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MovieID</th>\n",
       "      <th>List_Index</th>\n",
       "      <th>Rating</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UserID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>21</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>104</td>\n",
       "      <td>102</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>260</td>\n",
       "      <td>257</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        MovieID  List_Index  Rating\n",
       "UserID                             \n",
       "1             1           0       5\n",
       "2            21          20       1\n",
       "3           104         102       4\n",
       "4           260         257       5\n",
       "5             6           5       2"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Group up by UserID\n",
    "userGroup = merged_df.groupby('UserID')\n",
    "userGroup.first().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#Number of users used for training\n",
    "number_of_users = 1500\n",
    "trX = []\n",
    "\n",
    "for userID, current_user in userGroup:\n",
    "    temp = [0]*len(movies_df)\n",
    "    for num, movie in current_user.iterrows():\n",
    "        temp[movie['List_Index']] = movie['Rating']/5.0\n",
    "    trX.append(temp)\n",
    "    \n",
    "    if number_of_users == 0:\n",
    "        break\n",
    "    number_of_users -= 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "m = len(movies_df)\n",
    "n = 20\n",
    "recommender = rbm.RBM(m,n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epochs\n",
      "training epoch 0 cost 0.6689662337303162\n",
      "training epoch 1 cost 0.6393238306045532\n",
      "training epoch 2 cost 0.629054069519043\n",
      "training epoch 3 cost 0.6249909400939941\n",
      "training epoch 4 cost 0.6227217316627502\n",
      "training epoch 5 cost 0.6205174922943115\n",
      "training epoch 6 cost 0.6183570027351379\n",
      "training epoch 7 cost 0.6161996126174927\n",
      "training epoch 8 cost 0.6141089200973511\n",
      "training epoch 9 cost 0.6118001937866211\n"
     ]
    }
   ],
   "source": [
    "Xtrain = np.array(trX) \n",
    "init = tf.global_variables_initializer()\n",
    "with tf.Session() as sess:\n",
    "    sess.run(init)\n",
    "    recommender.set_session(sess)\n",
    "    err = recommender.fit(Xtrain, epochs=10)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.text.Text at 0x1d436b3ab70>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAAEKCAYAAAAB0GKPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl0nfV95/H3V5u1WKslW7J2wDbYllfZhkISgkOwTQKd\nTEkIi9MsZegJnaSdnjbpmXQ67ZxOO+k0SSfQlBhIWBImCxloADtpCJAmgC3Z8m6wMdbiTbYlWbZs\nWdt3/riPzbXi5WLr6tHV/bzOuQfuc3+6+uqC/dFvfczdERERuZiUsAsQEZHEoMAQEZGYKDBERCQm\nCgwREYmJAkNERGKiwBARkZgoMEREJCYKDBERiYkCQ0REYpIWdgEjqbi42GtqasIuQ0QkYTQ2Nh52\n95JY2o6rwKipqaGhoSHsMkREEoaZNcfaVkNSIiISk7gGhpktM7M3zWyXmX3pPG1uNLMmM9tqZq8E\n12YE104/us3si/GsVURELixuQ1Jmlgo8CNwMtAHrzOw5d98W1aYAeAhY5u4tZjYZwN3fBOZFvc9e\n4CfxqlVERC4unj2MxcAud9/t7n3A08Dtw9rcBTzj7i0A7t5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L\nsaSwtQDXmll28OdmKUmwCCDsO+6Fyt0HzOz0EeypwKPuvjXkssJ0PXAvsNnMmoJrf+HuL4RYk4wd\nfwQ8FfxytRv4dMj1hMbd3zCzHwHriawu3EAS7PrWTm8REYlJsg9JiYhIjBQYIiISEwWGiIjERIEh\nIiIxUWCIiEhMFBgiITKzG3USriQKBYaIiMREgSESAzO7x8zWmlmTmf1LcJ+M42b2teCeCL8ws5Kg\n7Twze93MNpnZT4JzhzCzq8zs38xso5mtN7Mrg7efGHWfiaeCncOY2d8F9ybZZGb/ENKPLnKGAkPk\nIszsGuATwPXuPg8YBO4GcoAGd58FvAL8t+BLHgf+3N3nAJujrj8FPOjuc4mcO7Q/uD4f+CKRe7Jc\nAVxvZpOA/wDMCt7nf8T3pxS5OAWGyMUtBRYC64IjU5YS+Yt9CPi/QZsngRuC+0YUuPsrwfXvAu83\ns1yg3N1/AuDuve5+Imiz1t3b3H0IaAJqgKNAL/CImX0MON1WJDQKDJGLM+C77j4veMxw9786R7tL\nPWfnVNS/DwJp7j5A5AZfPwI+Aqy+xPcWGTEKDJGL+wXwe2Y2GcDMisysmsifn98L2twF/Lu7HwU6\nzex9wfV7gVeCOxi2mdnvBu8xwcyyz/cNg3uS5AcHP/4xkVuiioQqqU+rFYmFu28zs/8K/MzMUoB+\n4PNEbiK0OHitncg8B8CngG8FgRB9quu9wL+Y2V8H73HHBb5tLvCsmWUS6eH8yQj/WCLvmU6rFblE\nZnbc3SeGXYfIaNGQlIiIxEQ9DBERiYl6GCIiEhMFhoiIxESBISIiMVFgiIhITBQYIiISEwWGiIjE\n5P8DwD5ee0jj/cwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1d436a94400>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(err)\n",
    "plt.xlabel('epochs')\n",
    "plt.ylabel('cost')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "user_index = 150\n",
    "x = np.array([Xtrain[user_index, :]])\n",
    "init = tf.global_variables_initializer()\n",
    "with tf.Session() as sess:\n",
    "    sess.run(init)\n",
    "    recommender.set_session(sess)\n",
    "    out = recommender.reconstruct(x.astype(np.float32))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MovieID</th>\n",
       "      <th>Title</th>\n",
       "      <th>Genre</th>\n",
       "      <th>List_Index</th>\n",
       "      <th>Recommendation_Score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Toy Story (1995)</td>\n",
       "      <td>Animation|Children's|Comedy</td>\n",
       "      <td>0</td>\n",
       "      <td>0.560319</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Jumanji (1995)</td>\n",
       "      <td>Adventure|Children's|Fantasy</td>\n",
       "      <td>1</td>\n",
       "      <td>0.699984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Grumpier Old Men (1995)</td>\n",
       "      <td>Comedy|Romance</td>\n",
       "      <td>2</td>\n",
       "      <td>0.751833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Waiting to Exhale (1995)</td>\n",
       "      <td>Comedy|Drama</td>\n",
       "      <td>3</td>\n",
       "      <td>0.894270</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Father of the Bride Part II (1995)</td>\n",
       "      <td>Comedy</td>\n",
       "      <td>4</td>\n",
       "      <td>0.238415</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   MovieID                               Title                         Genre  \\\n",
       "0        1                    Toy Story (1995)   Animation|Children's|Comedy   \n",
       "1        2                      Jumanji (1995)  Adventure|Children's|Fantasy   \n",
       "2        3             Grumpier Old Men (1995)                Comedy|Romance   \n",
       "3        4            Waiting to Exhale (1995)                  Comedy|Drama   \n",
       "4        5  Father of the Bride Part II (1995)                        Comedy   \n",
       "\n",
       "   List_Index  Recommendation_Score  \n",
       "0           0              0.560319  \n",
       "1           1              0.699984  \n",
       "2           2              0.751833  \n",
       "3           3              0.894270  \n",
       "4           4              0.238415  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score_movies_df = movies_df\n",
    "score_movies_df[\"Recommendation_Score\"] = out[0]\n",
    "score_movies_df.sort_values([\"Recommendation_Score\"],  ascending=False).head(20)\n",
    "score_movies_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "UID = merged_df.iloc[user_index]['UserID']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MovieID</th>\n",
       "      <th>Title</th>\n",
       "      <th>Genre</th>\n",
       "      <th>List_Index_x</th>\n",
       "      <th>Recommendation_Score</th>\n",
       "      <th>Rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1267</th>\n",
       "      <td>1287</td>\n",
       "      <td>Ben-Hur (1959)</td>\n",
       "      <td>Action|Adventure|Drama</td>\n",
       "      <td>1267</td>\n",
       "      <td>0.999996</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1094</th>\n",
       "      <td>1110</td>\n",
       "      <td>Bird of Prey (1996)</td>\n",
       "      <td>Action</td>\n",
       "      <td>1094</td>\n",
       "      <td>0.999995</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>235</th>\n",
       "      <td>238</td>\n",
       "      <td>Far From Home: The Adventures of Yellow Dog (1...</td>\n",
       "      <td>Adventure|Children's</td>\n",
       "      <td>235</td>\n",
       "      <td>0.999995</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>914</th>\n",
       "      <td>926</td>\n",
       "      <td>All About Eve (1950)</td>\n",
       "      <td>Drama</td>\n",
       "      <td>914</td>\n",
       "      <td>0.999991</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1460</th>\n",
       "      <td>1490</td>\n",
       "      <td>B*A*P*S (1997)</td>\n",
       "      <td>Comedy</td>\n",
       "      <td>1460</td>\n",
       "      <td>0.999989</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      MovieID                                              Title  \\\n",
       "1267     1287                                     Ben-Hur (1959)   \n",
       "1094     1110                                Bird of Prey (1996)   \n",
       "235       238  Far From Home: The Adventures of Yellow Dog (1...   \n",
       "914       926                               All About Eve (1950)   \n",
       "1460     1490                                     B*A*P*S (1997)   \n",
       "\n",
       "                       Genre  List_Index_x  Recommendation_Score  Rating  \n",
       "1267  Action|Adventure|Drama          1267              0.999996     NaN  \n",
       "1094                  Action          1094              0.999995     NaN  \n",
       "235     Adventure|Children's           235              0.999995     NaN  \n",
       "914                    Drama           914              0.999991     NaN  \n",
       "1460                  Comedy          1460              0.999989     NaN  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies_df_UID = merged_df[merged_df['UserID']==UID]\n",
    "merged_df_UID = pd.merge(score_movies_df,movies_df_UID, on='MovieID', how='outer')\n",
    "merged_df_UID = merged_df_UID.drop('List_Index_y', axis=1).drop('UserID', axis=1)\n",
    "merged_df_UID.sort_values([\"Recommendation_Score\"], ascending=False).head(5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:tf-gpu-1p3]",
   "language": "python",
   "name": "conda-env-tf-gpu-1p3-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
